const UTF8_ACCEPT: u32 = 0;
const UTF8_REJECT: u32 = 1;
static mut num_assert: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
macro_rules! assert {
    ($ expr : expr) => {
        unsafe {
            num_assert.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
        }
        if !$expr {
            panic!("Assertion failed: {}", stringify!($expr));
        }
    };
}
type UnitTestFunction = fn();
static UTF8D: &'static [u8; 400] = &[
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
    8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
    0xa, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, 0xb, 0x6, 0x6,
    0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x0, 0x1, 0x2, 0x3, 0x5, 0x8,
    0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1,
    1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
];
static TESTS: &[UnitTestFunction] = &[test_decode_chinese];
#[test]
fn test_decode_chinese() {
    let s = "成为更健康、更长久的世界一流企业";
    let mut res = [0u32; 64];
    let mut codepoint: u32;
    let mut count = 0;
    let mut state = 0;
    let bytes = s.as_bytes();
    for &byte in bytes.iter() {
        if decode_utf8(&mut state, &mut codepoint, byte) == 0 {
            res[count] = codepoint;
            count += 1;
        }
    }
    assert!(state == UTF8_ACCEPT);
    assert!(count == 16);
    assert!(res[1] == 0x4e3a);
    assert!(res[2] == 0x66f4);
    assert!(res[4] == 0x5eb7);
    assert!(res[8] == 0x4e45);
}
fn main() {
    run_tests(tests);
    println!("num_assert: {}", num_assert);
}
